import { GET_HOME_DATA } from "../constants/DPMessageConstants";

export function getHomeDataAction(dispatch, getState) {
  return new Promise(async (resove, inject) => {
    try {
      let res = await fetch("http://localhost:8080/json/GameJson.json", {
        mode: "no-cors"
      }).then(res => res.json());; //等待fetch被resolve()后才能继续执行

      dispatch({
        type: GET_HOME_DATA,
        data: {
          homeData: res
        }
      });
      resove(res);
    } catch (e) {
      console.log("error");
      inject(res);
    }
  });
}
